package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 推荐分类/目录
 */
@Setter
@Getter
@JsonIgnoreProperties("handler") //mybaits额外sql,有延时加载,动态代理对象的handler属性无法转换成json格式
public class StrategyCatalog {
    public static final boolean STATE_NORMAL = true; //启用
    public static final boolean STATE_DISPLAY = false; //禁用
    private Long id; //id

    private String name; //分类的名称

    private Strategy strategy;//所属的大区域
    private Integer sequence;//序号


    private Long strategyId; //大攻略的id
    //查询文章指定目录下面的文章
    private List<StrategyDetail> details = new ArrayList<>();
    private boolean state;//状态
    public String getStateDisplay(){
        if (state == STATE_NORMAL){
            return "启用";
        }else if (state==STATE_DISPLAY){
            return "禁用";
        }else {
            return "";
        }
    }
    //编辑框的回显
    public String getJsonString(){
        Map<String,Object> map = new HashMap<>();
        try {

            map.put("id",id);
            if ( strategy !=null){
                map.put("strategyId", strategy.getId());
            }
            map.put("name",name);
            map.put("sequence",sequence);
            map.put("state",state);
        }catch (Exception e){
            e.printStackTrace();

        }

        return JSONUtil.toJSONString(map);
    }

}